package IO流.IO流操作.处理流.字节缓冲流;

import java.io.*;

/**
 * 第二个IO程序：段落读取
 * 1.创建源
 * 2.选择流
 * 3.操作文件
 * 4.释放资源
 */
public class BufferedTest01 {
    public static void main(String[] args) {
        //1.创建源
       File src = new File("C:\\huangzhi\\workspace\\javaStudy\\src\\IO流\\IO流操作\\inputStream和outputStream\\输入流\\aaa.txt");
        //2.选择流
        InputStream inputStream = null;

        try {
            inputStream = new BufferedInputStream(new FileInputStream(src));
            //3.操作文件
           byte[] pool = new byte[1024];
           int len= -1;
           while ((len= inputStream.read(pool))!=-1){
               String str1 = new String(pool);
               String str = new String(pool,0,len);
               System.out.print(str);

           }
            inputStream.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                //若资源没有被用到，则不用关闭（若不判断会造成空指针异常）
                if (null != inputStream) {
                    inputStream.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        //4.释放资源
    }

}
